export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    permission: []
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      localStorage.setItem('token', token)
    },
    setPermission(state, permission) {
      state.permission = permission
    }
  },
  actions: {
    login({ commit }, { token, permission }) {
      commit('setToken', token)
      commit('setPermission', permission)
    }
  },
  getters: {
    havePermission: state => permission => {
      return state.permission.includes(permission)
    }
  }
}
